﻿using System.Net;
using Ramone;

namespace PrearrangedChaos.AgileZen.Service.Rest
{
    internal class ZenApiKeyRequestInterceptor : IRequestInterceptor
    {
        private readonly string _apiKey;
        private readonly int _connectionTimeout;
        private readonly int _readWriteTimeout;

        public ZenApiKeyRequestInterceptor(string apiKey, int connectionTimeout, int readWriteTimeout)
        {
            _apiKey = apiKey;
            _connectionTimeout = connectionTimeout;
            _readWriteTimeout = readWriteTimeout;
        }

        public void HeadersReady(RequestContext context)
        {
            HttpWebRequest request = context.Request;
            request.Headers.Add("X-Zen-ApiKey", this._apiKey);
            request.Timeout = this._connectionTimeout;
            request.ReadWriteTimeout = this._readWriteTimeout;
        }

        public void DataSent(RequestContext context)
        {
        }
    }
}
